package test.demo.Exception;

import com.sun.xml.internal.ws.developer.Serialization;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.ObjectUtils;
import test.demo.Error.ErrorCode;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@Serialization
public class BaseException extends RuntimeException {

    private final ErrorCode code;

    private final Map<String, Object> detail = new HashMap<>();

    public BaseException(ErrorCode code) {
        this.code = code;
    }

    public BaseException(ErrorCode code, Map<String, Object> params) {
        this.code = code;
        if (!ObjectUtils.isEmpty(params)) {
            this.detail.putAll(params);
        }
    }

    public BaseException(ErrorCode code, String msg) {
        this.code = code;
        HashMap<String, String> map = new HashMap<>();
        map.put("description", msg);
        detail.putAll(map);
    }
}